library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.3
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.0 v dplyr 0.8.5
## v tidyr 1.0.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 3.6.3
## Warning: package 'tibble' was built under R version 3.6.3
## Warning: package 'tidyr' was built under R version 3.6.3
## Warning: package 'purrr' was built under R version 3.6.3
## Warning: package 'dplyr' was built under R version 3.6.3
## Warning: package 'stringr' was built under R version 3.6.3
## Warning: package 'forcats' was built under R version 3.6.3
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(png)
library(grid)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
library(forcats)
library(mapview)
## Warning: package 'mapview' was built under R version 3.6.3
library(sf)
## Warning: package 'sf' was built under R version 3.6.3
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.6.3
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.6.3
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:dplyr':
##
## intersect, setdiff, union
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
# Get the Data
volcano <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-12/volcano.csv')
## Parsed with column specification:
## cols(
## .default = col_character(),
## volcano_number = col_double(),
## latitude = col_double(),
## longitude = col_double(),
## elevation = col_double(),
## population_within_5_km = col_double(),
## population_within_10_km = col_double(),
## population_within_30_km = col_double(),
## population_within_100_km = col_double()
## )
## See spec(...) for full column specifications.
eruptions <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-12/eruptions.csv')
## Parsed with column specification:
## cols(
## volcano_number = col_double(),
## volcano_name = col_character(),
## eruption_number = col_double(),
## eruption_category = col_character(),
## area_of_activity = col_character(),
## vei = col_double(),
## start_year = col_double(),
## start_month = col_double(),
## start_day = col_double(),
## evidence_method_dating = col_character(),
## end_year = col_double(),
## end_month = col_double(),
## end_day = col_double(),
## latitude = col_double(),
## longitude = col_double()
## )
events <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-12/events.csv')
## Parsed with column specification:
## cols(
## volcano_number = col_double(),
## volcano_name = col_character(),
## eruption_number = col_double(),
## eruption_start_year = col_double(),
## event_number = col_double(),
## event_type = col_character(),
## event_remarks = col_character(),
## event_date_year = col_double(),
## event_date_month = col_double(),
## event_date_day = col_double()
## )
tree_rings <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-12/tree_rings.csv')
## Parsed with column specification:
## cols(
## year = col_double(),
## n_tree = col_double(),
## europe_temp_index = col_double()
## )
sulfur <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-12/sulfur.csv')
## Parsed with column specification:
## cols(
## year = col_double(),
## neem = col_double(),
## wdc = col_double()
## )
volcano_plus_eruptions <- volcano %>%
left_join(by = "volcano_number", eruptions) %>%
filter(!is.na(start_year), !is.na(start_day), !is.na(end_day))%>%
mutate(start_date = make_date(start_year, start_month, start_day),
end_date = make_date(end_year,end_month, end_day)) %>%
filter(!is.na(start_date),
!is.na(end_date))%>%
mutate(duration = end_date - start_date)
volcano %>%
group_by(region) %>%
summarise(n = n())%>%
arrange(desc(n)) %>%
ggplot(aes(x = reorder(region, n), y = n)) +
geom_bar(stat = "identity") +
geom_text(aes(label = n), check_overlap = TRUE, nudge_y = 3) +
labs(title = "Number of volcanos by region") +
xlab("Name of region") +
ylab("number of volcanos")+
coord_flip()

volcano %>% ggplot(aes(x = major_rock_1)) + geom_bar() + facet_wrap(~region
) + coord_flip() + theme_classic()

volcano %>% filter(last_eruption_year != "Unknown")%>% ggplot(aes(y = population_within_10_km, x= as.integer(last_eruption_year), color = region)) + geom_point() + geom_smooth(method = lm, se = FALSE) + scale_y_log10() + xlab("last eruption year")
## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Transformation introduced infinite values in continuous y-axis
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 129 rows containing non-finite values (stat_smooth).

volcano %>%
st_as_sf(coords = c("longitude", "latitude"), crs =4326) %>%
mapview(zcol = "last_eruption_year", legend = TRUE, cex = "population_within_10_km")
volcano %>%
st_as_sf(coords = c("longitude", "latitude"), crs =4326) %>%
mapview(zcol = "major_rock_1")
volcano %>%
st_as_sf(coords = c("longitude", "latitude"), crs =4326) %>%
mapview(zcol = "major_rock_2")
volcano %>%
st_as_sf(coords = c("longitude", "latitude"), crs =4326) %>%
mapview(zcol = "major_rock_3")
volcano_plus_eruptions %>%
select(longitude.x, latitude.x, duration)%>%
mutate(dur_2 = as.integer(duration))%>%
as_tibble() %>%
st_as_sf(coords = c("longitude.x", "latitude.x"), crs =4326) %>%
mapview(zcol = "dur_2")